import VtBagTypeAPI from "./vt-bag-type.js";
import VtCompositeTypeAPI from "./vt-composite-type.js";
import VtMaterialAPI from "./vt-material.js";
import VtSizeAPI from "./vt-size.js";
import VtSurfaceFeeAPI from "./vt-surface-fee.js";
import VtAccessoryAPI from "./vt-accessory.js";
import VtRollAPI from "./vt-roll.js";

const VtOptionsAPI = {
  /**
   * 获取袋型选项数据
   * @param {number} type - 类型过滤，0=机印，1=现货数码印
   */
  getBagTypeOptions(type) {
    const params = { pageNum: 1, pageSize: 999 };
    if (type !== undefined && type !== null) {
      params.type = type;
    }
    return VtBagTypeAPI.getPage(params).then((data) => {
      return data.list.map((item) => ({
        label: `${item.name}${item.unitPrice ? `(${item.unitPrice}元/个)` : ""}`,
        value: item.name,
        id: item.id,
        type: item.type,
      }));
    });
  },

  /**
   * 获取复合工艺选项数据
   */
  getCompositeTypeOptions() {
    return VtCompositeTypeAPI.getPage({ pageNum: 1, pageSize: 999 }).then((data) => {
      return data.list.map((item) => ({
        label: `${item.name}(${item.unitPrice}元/m²${item.minFee ? `, 最低${item.minFee}元` : ""})`,
        value: item.name,
        unitPrice: item.unitPrice,
        minFee: item.minFee || 0,
        id: item.id,
      }));
    });
  },

  /**
   * 获取材质选项数据
   */
  getMaterialOptions() {
    return VtMaterialAPI.getPage({ pageNum: 1, pageSize: 999 }).then((data) => {
      return data.list.map((item) => ({
        label: `${item.name} (${item.thickness}) (${item.unitPrice}元/kg)`,
        value: `${item.name}-${item.thickness}`,
        id: item.id,
        density: item.density || 1000, // 密度 kg/m³，默认1000
        thickness: item.thickness, // 厚度（mm）
        editable: item.editable || 0, // 是否可编辑厚度，1=可编辑，0=不可编辑
      }));
    });
  },

  /**
   * 获取尺寸选项数据
   */
  getSizeOptions() {
    return VtSizeAPI.getPage({ pageNum: 1, pageSize: 999 }).then((data) => {
      return data.list.map((item) => ({
        label: `${item.l}×${item.w}${item.h ? "+" + item.h : ""}mm`,
        value: `${item.l}×${item.w}${item.h ? "+" + item.h : ""}`,
        id: item.id,
        l: item.l,
        w: item.w,
        h: item.h,
      }));
    });
  },

  /**
   * 获取印刷颜色选项数据
   */
  getSurfaceFeeOptions() {
    return VtSurfaceFeeAPI.getPage({ pageNum: 1, pageSize: 999 }).then((data) => {
      return data.list.map((item) => ({
        label: `${item.name}(${item.unitPrice}元/m²${item.minFee ? `, 最低${item.minFee}元` : ""})`,
        value: item.name,
        id: item.id,
        unitPrice: item.unitPrice,
        minFee: item.minFee || 0, // 最低印刷价格
      }));
    });
  },

  /**
   * 获取配件选项数据
   */
  getAccessoryOptions() {
    return VtAccessoryAPI.getPage({ pageNum: 1, pageSize: 999 }).then((data) => {
      return data.list.map((item) => ({
        label: `${item.name}(${item.unitPrice}元/${item.name === "纸箱" ? "个" : "m"})`,
        value: item.name,
        id: item.id,
        weight: item.weight,
      }));
    });
  },

  getRollOptions() {
    return VtRollAPI.getPage({ pageNum: 1, pageSize: 999 }).then((data) => {
      return data.list.map((item) => ({
        label: item.name,
        value: item.name,
        id: item.id,
        price: item.price,
        maxNum: item.maxNum,
      }));
    });
  },
};

export default VtOptionsAPI;
